home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sun Solutions 2000 #2
/
Sun Solutions CD (Volume 2 2000)(Special Focus - Java Technologies)(Disc 1).ISO
/
products
/
Software
/
BostonBusinessComputing
/
bbc
/
vmail.y
< prev
next >
Wrap
Text File
|
2000-02-11
|
3KB
|
135 lines
#!/bin/sh
test "/$argv[0]" = "/" && exec /bin/sh $0 $argv
(a=1; unset a) 2>/dev/null || {
[ "`uname -s 2>/dev/null`" = "ULTRIX" ] &&\
exec /bin/sh5 -$- $0 ${@+"$@"}
}
if [ -z "$BBC" ]; then
echo "$0: BBC environment variable not set. Can't continue." 1>&2
exit 1
fi
cleanup() {
status=$?
[ $status != 0 ] && echo "*** vmail exited with status $status"
[ -z "$VMVERSIONS" ] && exit 0
rm="rm -f $vmlocklink"
[ -n "$vmbackup" ] && cmp $vmfile $vmbackup >/dev/null 2>&1 && rm $vmbackup
rm="$rm `ls -r $vmfile~* 2>/dev/null | awk '{if (++i > '$VMVERSIONS') print $0}' | sort`"
exec $rm
}
error() {
echo "$0: $1" 1>&2
exit 1
}
vmdir=$HOME/vmail
vmrc=$vmdir/.vmailrc
id=`(whoami) 2>/dev/null || (id | sed 's/^[^(]*(\([^)]*\)).*/\1/')`
vmfile=$vmdir/MAIL.$id
vmlock=$vmdir/.vmaillock
vmlocklink="$vmlock"-link
host=`(hostname || uname -n) 2>/dev/null`
trap : 1
trap "cleanup" 0 1 2 3 4 5 6 7 8 10 12 13 15
if [ ! -d $vmdir ]; then
mkdir $vmdir || error "Couldn't create directory $vmdir"
fi
touch $vmlock
if ln $vmlock $vmlocklink >/dev/null 2>&1; then
echo " Host=$host
PID=$$
Date='`date`'
TTY=`tty`" > $vmlocklink
else
. $vmlock
if [ "$Host" != "$host" ]; then
state="may be"
else
if kill -1 $PID >/dev/null 2>&1; then
state="is"
else
rm -f $vmlocklink
exec $0 ${@+"$@"}
fi
fi
$BBC/tbput display \
"Another vmail process $state already using the
$vmfile mailbox file.
Here is the information about the other process:
`cat $vmlock`
You should exit from the other vmail process before proceeding.
File corruption will occur if two processes attempt to modify
the same mail file. Should I continue? "
read ans
case "$ans" in
y*) rm -f $vmlock; exec $0 ${@+"$@"}
esac
exit 0
fi
VMDEFAULT_VERSIONS=5
[ -r $BBC/vmailrc ] && . $BBC/vmailrc
[ ! -r $vmrc -a -n "$VMFORCEDEFAULT" ] && \
echo "VMVERSIONS=$VMDEFAULT_VERSIONS" > $vmrc
while [ ! -r $vmrc ]; do
$BBC/tbput display \
"Vmail has the ability to make backup copies of its saved mail files.
How many versions of the vmail mail files would you like to save? ($VMDEFAULT_VERSIONS) "
read num || exit 1
[ -z "$num" ] && num=$VMDEFAULT_VERSIONS
n="`expr $num + 0 2>/dev/null`"
if [ -z "$n" ]; then
echo "Please enter a number."
continue
fi
if [ "$num" -lt 0 ]; then
echo "Please enter a positive number."
continue
fi
if [ "$num" -eq 0 ]; then
$BBC/tbput display \
"We recommend that you keep at least one backup copy.
Are you sure that you don't want any backups to be made? "
read ans
case "$ans" in
y*) ;;
n*) continue
esac
fi
echo "
*** Modifying the file $vmrc.
*** Edit this file in the future if you would like to change the number of
*** mail file backup versions.
"
echo "VMVERSIONS=$num" > $vmrc || error "Couldn't create file $vmrc"
done
. $vmrc
if [ "$VMVERSIONS" -eq 0 ]; then
vmbackup=''
else
numver=0
maxver=0
for f in $vmfile~*; do
ver=`expr $f : "$vmdir/MAIL\.$id~\(.*\)$"`
[ "$ver" = '*' ] && break
[ "$ver" -gt "$maxver" ] && maxver="$ver"
numver=`expr $numver + 1`
done
vmbackup="$vmfile"`awk 'BEGIN{printf "~%05d", '"$maxver"' + 1}'</dev/null`
[ -r $vmfile ] && cp $vmfile $vmbackup
fi
trap : 2 3
$BBC/vmail.x ${@+"$@"}